/*
* jlb
*/
package com.jlb.user.ctrl;

import com.alibaba.fastjson.JSON;
import com.jlb.user.entity.User;
import com.jlb.user.service.UserSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.user.entity.UserActive;
import com.jlb.user.service.UserActiveSV;

/**
 * 用户具备的激活币 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/userActive")
@Slf4j
@Api(value = "用户具备的激活币控制器", description = "用户具备的激活币控制器")
public class UserActiveCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private UserActiveSV userActiveSV;

    @Resource
    private UserSV userSV;

    /**
     * 查询UserActive一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询UserActive一个详情信息", notes = "查询UserActive一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id) {
        if (id == null) {
            return null;
        }
        UserActive userActive = userActiveSV.load(id);
        log.info(JSON.toJSONString(userActive));
        return BeanRet.create(true, "查询成功", userActive);
    }


    /**
     * 根据条件id查询UserActive一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询UserActive一个详情信息", notes = "查询UserActive一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        UserActive userActive = userActiveSV.loadById(id);
        log.info(JSON.toJSONString(userActive));
        return BeanRet.create(true, "查询成功", userActive);
    }


    /**
     * 查询UserActive信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询UserActive信息集合", notes = "查询UserActive信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "账户", required = true, paramType = "query"),
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(String account, @ApiIgnore UserActive userActive, Integer curPage, Integer pageSize) {
        Page<UserActive> page = new Page<UserActive>(pageSize, curPage);
        if (StringUtils.isNotBlank(account)) {
            User user = userSV.loadByAccount(account);
            if (user == null) {
                return BeanRet.create(true, "查询成功", page);
            }
            userActive.setUserCode(user.getCode());
        }
        List<UserActive> userActives = userActiveSV.list(userActive, page.genRowStart(), page.getPageSize());
        page.setVoList(userActives);
        int total = userActiveSV.count(userActive);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);

    }


    /**
     * 查询UserActive信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询UserActive信息集合", notes = "查询UserActive信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id, Integer curPage, Integer pageSize) {
        Page<UserActive> page = new Page<UserActive>(pageSize, curPage);
        List<UserActive> userActives = userActiveSV.list(id, page.genRowStart(), page.getPageSize());
        page.setVoList(userActives);
        int total = userActiveSV.count(id);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 统计UserActive信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计UserActive信息数量根据主键", notes = " 统计UserActive信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id) {
        return userActiveSV.count(id);
    }

    /**
     * 统计UserActive信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计UserActive信息数量", notes = "统计UserActive信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "activeCode", value = "激活码", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore UserActive userActive) {
        if (userActive == null) {
            return userActiveSV.count(new HashMap());
        } else {
            return userActiveSV.count(userActive);
        }
    }


    /**
     * 创建UserActive
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建UserActive", notes = "创建UserActive")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "activeCode", value = "激活码", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore UserActive userActive) {
        userActiveSV.save(userActive);
        return BeanRet.create(true, "创建成功", userActive);
    }


    /**
     * 修改UserActive
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改UserActive", notes = "修改UserActive")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "activeCode", value = "激活码", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore UserActive userActive) {
        userActiveSV.modify(userActive);
        return BeanRet.create(true, "修改成功", userActive);
    }

    /**
     * 删除UserActive
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除UserActive", notes = "删除UserActive")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id) {
        userActiveSV.delete(id);
        return BeanRet.create(true, "删除UserActive成功");
    }

}
